<template>
	<view class="top">
		<view class="userinfo">
			<view class="img-box" v-if="userInfo.avatar!=null">
				<image :src="userInfo.avatar" class="img" @click="toLogin"></image> 
			</view>
			<view class="img-box" v-if="userInfo.avatar==null">
				<image src="../../static/images/user/touxiang.png" class="img" @click="toLogin"></image> 
			</view>
			<view class="userinfo-1">
				<view v-if="isLogin">
					<view class="userinfo-2" v-if="userInfo.name!=null">
						{{userInfo.name}}
					</view>
					<view class="userinfo-2" v-if="userInfo.name==null">
						微信用户
					</view>
					<view class="userinfo-3" style="color: white;">
						余额：{{userInfo.account}}元
					</view>
				</view>
				<view v-if="!isLogin" class="btn_lable" style="margin-top:50rpx;font-size: 25rpx;">登录</view>
			</view>
			<view class="juese">
				<view class="btn_lable-1" v-if="identityStatus.administrator">
					<image src="../../static/icon-renzheng.png" class="icon-renzheng"></image> 平台管理员
				</view>
				<view class="btn_lable-1" v-if="identityStatus.cityPartner">
					<image src="../../static/icon-renzheng.png" class="icon-renzheng"></image> 城市合伙人
				</view>
				<view class="btn_lable-1" v-if="identityStatus.butler">
					<image src="../../static/icon-renzheng.png" class="icon-renzheng"></image>社区管家
				</view>
				<view class="btn_lable-1" v-if="identityStatus.assistant">
					<image src="../../static/icon-renzheng.png" class="icon-renzheng"></image>小助理
				</view>
				<view class="btn_lable-1" v-if="identityStatus.shop">
					<image src="../../static/icon-renzheng.png" class="icon-renzheng"></image>商家
				</view>
				<view class="btn_lable-1" v-if="identityStatus.lawyer">
					<image src="../../static/icon-renzheng.png" class="icon-renzheng"></image>律师
				</view>
				<view class="btn_lable-1">
					<image src="../../static/icon-renzheng.png" class="icon-renzheng"></image>普通用户
				</view>
			</view>
		</view>
	</view>
	<view class="menu_00">
		<view class="menu_00_titile">
			服务订单
			<label class="menu_00_more" @click="order(null)">
				全部
				<image src="../../static/gengduo@3x(1).png" class="menu_00_more_img"></image>
			</label>
		</view>
		<view class="menu_00_10">
			<view class="menu" @click="order(0)">
				<view class="menu_img">
					<image src="../../static/menu_dfk.png" class="icon-menu"></image>
				</view>
				<!-- <view class="jioabiao">
					3
				</view> -->
				<view class="menu_lable">
					待付款
				</view>
			</view>
			<view class="menu" @click="order(1)">
				<view class="menu_img">
					<image src="../../static/menu_dsy.png" class="icon-menu"></image>
				</view>
				<!-- <view class="jioabiao">
					5
				</view> -->
				<view class="menu_lable">
					待使用
				</view>
			</view>
			<view class="menu" @click="order(2)">
				<view class="menu_img">
					<image src="../../static/menu_dpl.png" class="icon-menu"></image>
				</view>
				<!-- <view class="jioabiao">
					52
				</view> -->
				<view class="menu_lable">
					待评论
				</view>
			</view>
			<view class="menu" @click="order(3)">
				<view class="menu_img">
					<image src="../../static/menu_dptk.png" class="icon-menu"></image>
				</view>
				<!-- <view class="jioabiao">
					6
				</view> -->
				<view class="menu_lable">
					退款
				</view>
			</view>
		</view>
		<!-- <view class="menu_00_titile">
			任务管理
			<label class="menu_00_more">
				全部
				<image src="../../static/gengduo@3x(1).png" class="menu_00_more_img"></image>
			</label>
		</view>
		<view class="menu_00_10">
			<view class="menu">
				<view class="menu_img">
					<image src="../../static/dlq.png" class="icon-menu"></image>
				</view>
				<view class="jioabiao">
					3
				</view>
				<view class="menu_lable">
					待领取
				</view>
			</view>
			<view class="menu">
				<view class="menu_img">
					<image src="../../static/ylq.png" class="icon-menu"></image>
				</view>
				<view class="jioabiao">
					5
				</view>
				<view class="menu_lable">
					已领取
				</view>
			</view>
			<view class="menu">
				<view class="menu_img">
					<image src="../../static/ywc.png" class="icon-menu"></image>
				</view>
				<view class="jioabiao">
					52
				</view>
				<view class="menu_lable">
					已完成
				</view>
			</view>
			<view class="menu">
				<view class="menu_img">
					<image src="../../static/yqx.png" class="icon-menu"></image>
				</view>
				<view class="jioabiao">
					6
				</view>
				<view class="menu_lable">
					已取消
				</view>
			</view>
		</view> -->

		<view class="menu_00_10" style="border-top: 3rpx solid #8a8a8a;">
			<view class="menu-1" @click="toFormCityPartner">
				<view class="menu_img">
					<image src="../../static/quyu.png" class="icon-menu"></image>
				</view>
				<view class="menu_lable">
					合伙人
				</view>
			</view>
			<view class="menu-1" @click="toFormShop" v-if="identityStatus.shop!=1">
				<view class="menu_img">
					<image src="../../static/shangjia.png" class="icon-menu"></image>
				</view>
				<view class="menu_lable">
					商家申请
				</view>
			</view>
			<view class="menu-1" @click="toFormButler()" v-if="identityStatus.butler!=1">
				<view class="menu_img">
					<image src="../../static/guanjia.png" class="icon-menu"></image>
				</view>

				<view class="menu_lable">
					管家申请
				</view>
			</view>
<!-- 			<view class="menu-1" @click="toFormAssistant()" v-if="!identityStatus.assistant">
				<view class="menu_img">
					<image src="../../static/zhuli.png" class="icon-menu"></image>
				</view>
				<view class="menu_lable">
					小助理申请
				</view>
			</view> -->
	<!-- 		<view class="menu-1" @click="toFormCityPartnerBackend" v-if="identityStatus.cityPartner">
				<view class="menu_img">
					<image src="../../static/houtai_1.png" class="icon-menu"></image>
				</view>
				<view class="menu_lable">
					区域后台
				</view>
			</view> -->
			<view class="menu-1">
				<view class="menu_img" @click="shopLogin()" >
					<image src="../../static/houtai_3.png" class="icon-menu"></image>
				</view>
				<view class="menu_lable">
					商家后台
				</view>
			</view>
			<view class="menu-1" v-if="identityStatus.butler">
				<view class="menu_img" @click="butler()">
					<image src="../../static/houtai_4.png" class="icon-menu"></image>
				</view>
				<view class="menu_lable">
					管家后台
				</view>
			</view>
			<!-- <view class="menu-1" v-if="identityStatus.assistant">
				<view class="menu_img">
					<image src="../../static/houtai1.png" class="icon-menu"></image>
				</view>
				<view class="menu_lable">
					小助手后台
				</view>
			</view> -->
			<!-- <view class="menu-1" @click="dizhi()">
				<view class="menu_img">
					<image src="../../static/dingwei.png" class="icon-menu"></image>
				</view>
				<view class="menu_lable">
					地址管理
				</view>
			</view> -->
			<!-- <view class="menu-1" @click="poster()">
				<view class="menu_img">
					<image src="../../static/fenxiang.png" class="icon-menu"></image>
				</view>
				<view class="menu_lable">
					分享海报
				</view>
			</view> -->
			<view class="menu-1" @click="contact()">
				<view class="menu_img">
					<image src="../../static/lianxi.png" class="icon-menu"></image>
				</view>
				<view class="menu_lable">
					联系我们
				</view>
			</view>
			<view class="menu-1" @click="shezhi()" v-if="identityStatus.shop==1||identityStatus.cityPartner==1">
				<view class="menu_img">
					<image src="../../static/shezhi.png" class="icon-menu"></image>
				</view>
				<view class="menu_lable">
					后台申请
				</view>
			</view>
			<view class="menu-1" @click="distribution()">
				<view class="menu_img">
					<image src="../../static/shezhi.png" class="icon-menu"></image>
				</view>
				<view class="menu_lable">
					分销返佣
				</view>
			</view>
			<view style="width: 100%;height: 30rpx;float: left;"></view>
		</view>
	</view>

</template>

<script setup>
	import http from '../../utils/http';
	const user=ref();
	import {
		onLoad,onShow,
		onPageScroll
	} from '@dcloudio/uni-app';
	onLoad((query) => {
		 getApp().getUserInfo();
		 if(!getApp().globalData.user.userId){
		 	uni.navigateTo({
		 		url: "/pages/login/login"
		 	});
		 	return;
		 }
		 userInfo.value=getApp().globalData.user;
		 if(userInfo.value.avatar==""){
		 	userInfo.value.avatar="../../static/images/user/touxiang.png"
		 }
		 if(userInfo.value.name==""){
		 	userInfo.value.avatar="微信用户"
		 }
	})
	function distribution(){
		uni.navigateTo({
			url: "/pages/distribution/login"
		});
	}
	onShow(() => {
		getApp().getUserInfo();
		if(!getApp().globalData.user.userId){
			uni.navigateTo({
				url: "/pages/login/login"
			});
			return;
		}
		userInfo.value=getApp().globalData.user;
		if(userInfo.value.avatar==""){
			userInfo.value.avatar="../../static/images/user/touxiang.png"
		}
		if(userInfo.value.name==""){
			userInfo.value.avatar="微信用户"
		}
	})
	const isLogin = ref(true);
	const userInfo = ref({})
	const loginUrl = ref("")
	function toLogin() {
		uni.navigateTo({
			url: "/pages/login/edit"
		}) 
	}
	function order(status){
		uni.navigateTo({
			url: "/pages/order/order?status="+status
		})
	}
	function shopLogin(){
		wx.getStorage({
		  key: 'shopUserId',
		  success (res) {
			  if(res.data!=-1){
				  console.log("bbbbbbbbbbbbbbbbbbbbbb",getApp().globalData.shopUserId)
				 getApp().globalData.shopUserId=res.data; 
			  } 
		  }
		})
		
		console.log("aaaaaaaaaaaaaaaaaa",getApp().globalData.shopUserId)
		if(getApp().globalData.shopUserId==''){
			uni.navigateTo({
				url: "/pages/my/shop/login"
			})
		}else{
			uni.navigateTo({
				url: "/pages/my/shop/shop"
			})
		}
	}
	function toFormCityPartner() { 
		uni.navigateTo({
			url: "/pages/my/manage/partner"
		})
	}

	function toFormCityPartnerBackend() { 
		uni.navigateTo({
			url: "/pages/my/manage/partner"
		})
	}

	function toFormShop() {
		if(getApp().globalData.user.shop > 1){
			uni.navigateTo({
				url: "/pages/result/result?type=1"
			})
			return;
		}
		uni.navigateTo({
			url: "/pages/application/form_shop"
		})
	}
	
	function toFormButler() {
		
		if(getApp().globalData.user.butler > 1){
			uni.navigateTo({
				url: "/pages/result/result?type=2"
			})
			return;
		}
		 
		uni.navigateTo({
			url: "/pages/application/form_butler"
		})
	}
	function butler(){
		uni.navigateTo({
			url: "/pages/my/butler/index"
		})
	}
	function toFormAssistant() {
		if(getApp().globalData.user.assistant == 1){
			uni.showToast({
				icon:'none',
				title:"您已是小助手"
			})
			return;
		}
		uni.navigateTo({
			url: "/pages/application/form_assistant"
		})
	}

	function shezhi() {
		uni.navigateTo({
			url: '/pages/my/install/index'
		});
	}

	function dizhi() {
		uni.navigateTo({
			url: '/pages/address/address'
		});
	}

	function poster() {
		uni.navigateTo({
			url: '/pages/my/poster/poster'
		});
	}

	function contact() {
		uni.navigateTo({
			url: '/pages/my/contact/contact'
		});
	}

	function checkUserIdentity(userInfo) {
		console.log(userInfo)
		
		return {
			administrator: userInfo.administrator ===1,
			cityPartner: userInfo.cityPartner === 1,
			butler: userInfo.butler === 1,
			assistant: userInfo.assistant === 1,
			shop: userInfo.shop === 1,
			lawyer: userInfo.lawyer === 1,
		};

	}

	const identityStatus = ref(checkUserIdentity(getApp().globalData.user));


	onShow(() => {
		console.log("111111111111111111")
		identityStatus.value = checkUserIdentity(getApp().globalData.user);
	})
</script>

<style>
	.icon-renzheng {
		width: 23rpx;
		height: 23rpx;
		margin-top: 4rpx;
		float: left;
		margin-right: 5rpx;
	}

	.btn_lable-1 {
		width: auto;
		float: left;
		height: 30rpx;
		line-height: 30rpx;
		border: #969696 3rpx solid;
		border-radius: 10rpx;
		padding-left: 7rpx;
		padding-right: 7rpx;
		margin-right: 20rpx;
		font-size: 22rpx;
		color: #969696;
	}

	.menu_00_10 {
		width: 90%;
		float: left;
		margin-top: 15rpx;
		height: auto;
		margin-left: 5%;
		font-size: 30rpx;
		line-height: 60rpx;
	}

	.menu_00_more_img {
		width: 23rpx;
		height: 23rpx;
		margin-top: 21rpx;
		float: right;
	}

	.menu_00_more {
		float: right;
		margin-right: 30rpx;
		font-size: 24rpx;
		color: #A5AAB3;
		font-weight: 100;
	}

	.menu_00_titile {
		width: 95%;
		float: left;
		margin-top: 5rpx;
		height: 60rpx;
		margin-left: 5%;
		font-size: 26rpx;
		line-height: 60rpx;
		font-weight: bold;
	}

	.menu_00 {
		width: 88%;
		height: auto;
		float: left;
		background: white;
		border-radius: 20rpx;
		margin-left: 6%;
		margin-top: -70rpx;
	}

	.icon-menu {
		width: 70rpx;
		height: 70rpx;
	}

	.jioabiao {
		width: 30rpx;
		height: 30rpx;
		float: right;
		background: #FF8100;
		border-radius: 30rpx;
		margin-top: -90rpx;
		margin-right: 30rpx;
		color: white;
		line-height: 30rpx;
		font-size: 20rpx;
	}

	.menu_lable {
		width: 100%;
		float: left;
		font-size: 23rpx;
		line-height: 35rpx;
	}

	.menu {
		width: 25%;
		float: left;
		height: 130rpx;
		text-align: center;
		margin-top: 20rpx;
	}

	.menu-1 {
		width: 25%;
		float: left;
		height: 130rpx;
		text-align: center;
		margin-top: 40rpx;
	}

	.menu_img {
		width: 100%;
		float: left;
		height: 80rpx;
	}

	Page {
		background-color: #F2F2F2;
		font-size: 30rpx;
	}

	.juese {
		width: 100%;
		float: left;
		font-size: 25rpx;
		margin-top: 20rpx;
	}

	.userinfo-2 {
		width: 100%;
		float: left;
		font-size: 35rpx;
		margin-top: 10rpx;
	}

	.userinfo-3 {
		width: 100%;
		float: left;
		font-size: 35rpx;
		margin-top: 10rpx;
		color: #515151;
		font-size: 26rpx;
	}

	.userinfo-1 {
		width: 400rpx;
		height: 130rpx;
		float: left;
		margin-left: 20rpx;
	}

	.img {
		width: 150rpx;
		height: 150rpx;
	}

	.img-box {
		width: 150rpx;
		height: 150rpx;
		float: left;
		border-radius: 150rpx;
		overflow: hidden;
	}

	.userinfo {
		width: 90%;
		height: 200rpx;
		float: left;
		margin-top: 150rpx;
		margin-left: 5%;
	}

	.top {
		width: 100%;
		height: 450rpx;
		background: #2AE8DC;
		color: white;
	}

	.btn_lable {
		width: auto;
		float: left;
		height: 40rpx;
		line-height: 40rpx;
		border: white 4rpx solid;
		border-radius: 10rpx;
		padding-left: 10rpx;
		padding-right: 10rpx;
		margin-right: 20rpx;
	}
</style>